package zj.it.bhne.gridengineeringsurvey.activity;

import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.view.View;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.TextView;

import zj.it.bhne.gridengineeringsurvey.BaseActivity;
import zj.it.bhne.gridengineeringsurvey.R;
import zj.it.bhne.gridengineeringsurvey.fragment.details.BasisFragment;
import zj.it.bhne.gridengineeringsurvey.fragment.details.CrossFragment;
import zj.it.bhne.gridengineeringsurvey.fragment.details.ElectricityFragment;
import zj.it.bhne.gridengineeringsurvey.fragment.details.MaterialFragment;
import zj.it.bhne.gridengineeringsurvey.fragment.details.PoleFragment;

/**
 * 項目下拉列表中詳情活动
 */
public class DetailsActivity extends BaseActivity implements View.OnClickListener {

    public static Long DATA;
    private Long details;
    private Long de_id;
    private Context context;
    private Button de_jichu;
    private Button de_ganta;
    private Button de_jiaocha;
    private Button de_kuayue;
    private Button de_yongdian;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_details);
        initView();
        context = this;
        Intent intent = getIntent();
        details = intent.getLongExtra("details", 0);
        de_id = intent.getLongExtra("de_id", 0);
        DATA = details;
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        finish();
    }

    @Override
    protected void onStop() {
        super.onStop();
        finish();
    }

    private void initView() {
        ImageButton activity_ib_back = findViewById(R.id.activity_ib_back);
        TextView activity_tv_title = findViewById(R.id.activity_tv_title);
        TextView activity_tv_save = findViewById(R.id.activity_tv_save);
        activity_tv_title.setText(getString(R.string.title_xiangqing));
        activity_tv_save.setText("");
        activity_ib_back.setOnClickListener(this);
        de_jichu = findViewById(R.id.de_jichu);
        de_jichu.setOnClickListener(this);
        de_ganta = findViewById(R.id.de_ganta);
        de_ganta.setOnClickListener(this);
        de_jiaocha = findViewById(R.id.de_jiaocha);
        de_jiaocha.setOnClickListener(this);
        de_kuayue = findViewById(R.id.de_kuayue);
        de_kuayue.setOnClickListener(this);
        de_yongdian = findViewById(R.id.de_yongdian);
        de_yongdian.setOnClickListener(this);
        changeFragment(new BasisFragment());
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.activity_ib_back:
                Intent intent = new Intent(context, BottomActivity.class);
                intent.putExtra("item_id", de_id);
                startActivity(intent);
                finish();
                break;
            case R.id.de_jichu:
                BasisFragment myFragment = new BasisFragment();
                Bundle bundle = new Bundle();
                bundle.putLong("DATA", details);//这里的values就是我们要传的值
                myFragment.setArguments(bundle);
                changeFragment(new BasisFragment());
                de_jichu.setBackgroundResource(R.drawable.btn_shape);
                de_ganta.setBackgroundResource(R.drawable.btn_shape_white);
                de_jiaocha.setBackgroundResource(R.drawable.btn_shape_white);
                de_kuayue.setBackgroundResource(R.drawable.btn_shape_white);
                de_yongdian.setBackgroundResource(R.drawable.btn_shape_white);
                de_jichu.setTextColor(Color.rgb(255, 255, 255));
                de_ganta.setTextColor(Color.rgb(51, 51, 51));
                de_jiaocha.setTextColor(Color.rgb(51, 51, 51));
                de_kuayue.setTextColor(Color.rgb(51, 51, 51));
                de_yongdian.setTextColor(Color.rgb(51, 51, 51));
                break;
            case R.id.de_ganta:
                PoleFragment myFragment1 = new PoleFragment();
                Bundle bundle1 = new Bundle();
                bundle1.putLong("DATA", details);//这里的values就是我们要传的值
                myFragment1.setArguments(bundle1);
                changeFragment(new PoleFragment());
                de_jichu.setBackgroundResource(R.drawable.btn_shape_white);
                de_ganta.setBackgroundResource(R.drawable.btn_shape);
                de_jiaocha.setBackgroundResource(R.drawable.btn_shape_white);
                de_kuayue.setBackgroundResource(R.drawable.btn_shape_white);
                de_yongdian.setBackgroundResource(R.drawable.btn_shape_white);
                de_jichu.setTextColor(Color.rgb(51, 51, 51));
                de_ganta.setTextColor(Color.rgb(255, 255, 255));
                de_jiaocha.setTextColor(Color.rgb(51, 51, 51));
                de_kuayue.setTextColor(Color.rgb(51, 51, 51));
                de_yongdian.setTextColor(Color.rgb(51, 51, 51));
                break;
            case R.id.de_jiaocha:

                CrossFragment crossmyFragment = new CrossFragment();
                Bundle bundlejiaocha = new Bundle();
                bundlejiaocha.putLong("DATA", details);//这里的values就是我们要传的值
                crossmyFragment.setArguments(bundlejiaocha);
                changeFragment(crossmyFragment);
                de_jichu.setBackgroundResource(R.drawable.btn_shape_white);
                de_ganta.setBackgroundResource(R.drawable.btn_shape_white);
                de_jiaocha.setBackgroundResource(R.drawable.btn_shape);
                de_kuayue.setBackgroundResource(R.drawable.btn_shape_white);
                de_yongdian.setBackgroundResource(R.drawable.btn_shape_white);
                de_jichu.setTextColor(Color.rgb(51, 51, 51));
                de_ganta.setTextColor(Color.rgb(51, 51, 51));
                de_jiaocha.setTextColor(Color.rgb(255, 255, 255));
                de_kuayue.setTextColor(Color.rgb(51, 51, 51));
                de_yongdian.setTextColor(Color.rgb(51, 51, 51));
                break;
            //TODO 2019年4月3日修改的内容
            case R.id.de_kuayue:
                changeFragment(new MaterialFragment());
                de_jichu.setBackgroundResource(R.drawable.btn_shape_white);
                de_ganta.setBackgroundResource(R.drawable.btn_shape_white);
                de_jiaocha.setBackgroundResource(R.drawable.btn_shape_white);
                de_kuayue.setBackgroundResource(R.drawable.btn_shape);
                de_yongdian.setBackgroundResource(R.drawable.btn_shape_white);
                de_jichu.setTextColor(Color.rgb(51, 51, 51));
                de_ganta.setTextColor(Color.rgb(51, 51, 51));
                de_jiaocha.setTextColor(Color.rgb(51, 51, 51));
                de_kuayue.setTextColor(Color.rgb(255, 255, 255));
                de_yongdian.setTextColor(Color.rgb(51, 51, 51));
                break;
            case R.id.de_yongdian:
                changeFragment(new ElectricityFragment());
                de_jichu.setBackgroundResource(R.drawable.btn_shape_white);
                de_ganta.setBackgroundResource(R.drawable.btn_shape_white);
                de_jiaocha.setBackgroundResource(R.drawable.btn_shape_white);
                de_kuayue.setBackgroundResource(R.drawable.btn_shape_white);
                de_yongdian.setBackgroundResource(R.drawable.btn_shape);
                de_jichu.setTextColor(Color.rgb(51, 51, 51));
                de_ganta.setTextColor(Color.rgb(51, 51, 51));
                de_jiaocha.setTextColor(Color.rgb(51, 51, 51));
                de_kuayue.setTextColor(Color.rgb(51, 51, 51));
                de_yongdian.setTextColor(Color.rgb(255, 255, 255));
                break;
        }
    }

    private void changeFragment(Fragment fragment) {
        FragmentManager manager = getSupportFragmentManager();
        FragmentTransaction transaction = manager.beginTransaction();
        transaction.replace(R.id.de_content, fragment);
        transaction.commit();
    }


}
